package cz.proks.easyhelpdesk.gwt.restapi;

import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONValue;

import cz.proks.easyhelpdesk.api.model.OAuth2Token;
import cz.proks.easyhelpdesk.gwt.jso.GoogleUser;
import cz.proks.easyhelpdesk.gwt.utils.RestUtils;

public class GoogleRestApi {
    
    public void getGoogleUserInfo(OAuth2Token token, final DomainCallback<GoogleUser> callback) {
        RestUtils.makeSignedRestRequest("/google-apis/oauth2/v2/userinfo", token.getAccessToken(), new RestUtils.Callback(callback) {
    
            @Override
            public void onSuccess(JSONValue val) {
                JSONObject jsonObject = val.isObject();
                GoogleUser user = (GoogleUser) jsonObject.getJavaScriptObject();
                
                callback.onDomainSuccess(user);                
            }
        });
    }
}
